using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using Pulog.Models;

namespace Pulog.Controllers
{
    public class SearchFormViewModel
    {
        // Properties
        public List<Post> Posts { get; private set; }

        // Constructor
        public SearchFormViewModel(List<Post> posts)
        {
            List<Post> p = posts;
        }
    }

    public class SearchController : Controller
    {
        PostRepository postRepository = new PostRepository();

        public ActionResult Index(string searchTerm, string searchMode, int? pageIndex)
        {
            if (!string.IsNullOrEmpty(searchTerm))
            {
                PagedList<Post> posts = postRepository.SearchPosts(searchTerm, searchMode, pageIndex);
                TempData["searchTerm"] = searchTerm;
                return View("Search",posts);
            }
            else
            {
                return View("Search");
            }
        }

    }
}
